// QueuedCommand.cs
//
//  Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
using System.Collections.Generic;

namespace Whitemice.ZOGI.Backend
{
  internal class QueuedCommand : IComparable
  {
    private IZOGICommand  command;
    private bool          popped;
    private DateTime      t1, t2, t3;
    private List<Entity>  cache;
    
    public QueuedCommand(IZOGICommand c, List<Entity> x)
    {
      cache = new List<Entity>();
      command = c;
      popped = false;
      cache = x;
      t1 = t2 = t3 = DateTime.Now;
    } // end ctor
    
    public IZOGICommand Command
    {
      get { return command; }
      set { command = value; }
    } // end Command
    
    internal IZOGICommand Pop()
    {
      t2 = DateTime.Now;
      popped = true;
      return Command;
    } // end Pop
    
    public List<Entity> CachedObjects
    {
      get { return cache; }
    }
    
    public RpcPriority Priority { get { return command.Priority; } }
    public DateTime    Issued   { get { return command.Issued; } }
    public bool        Popped   { get { return popped; } }
    
    public int CompareTo(object obj)
    {
      if (obj is QueuedCommand)
      {
        QueuedCommand other = (obj as QueuedCommand);
        
        if (this.Priority > other.Priority)
          return (-1);
        if (this.Priority < other.Priority)
          return (1);
        return this.Issued.CompareTo(other.Issued);
      }
      return 0;
    } // end CompareTo
  } // end class
}
